home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / TSR2.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  5KB  |  154 lines

  1. ;**********************************;
  2. ; WASM TSR Support, Resident Query ;
  3. ; By Eric Tauck                    ;
  4. ;                                  ;
  5. ; Defines:                         ;
  6. ;                                  ;
  7. ;   Trap21  hook interrupt 21      ;
  8. ;   Free21  release interrupt 21   ;
  9. ;   Okay21  verify interrupt 21    ;
  10. ;   Query   query resident TSR     ;
  11. ;                                  ;
  12. ; Requires:                        ;
  13. ;                                  ;
  14. ;   INTR.ASM                       ;
  15. ;**********************************;
  16.  
  17. ; Note: program must define: TSR_ID1, TSR_ID2, and TsrUsr.
  18.   
  19.         jmps    _tsr2_end
  20.  
  21. _tsr_int21      LABEL   DWORD
  22.                 DS      4
  23.  
  24. ;========================================
  25. ; Macro to hook the INT 21H hander.
  26.  
  27. Trap21  MACRO
  28.  
  29. ;--- save old interrupt
  30.  
  31.         mov     al, 21H                 ;interrupt number
  32.         call    IntGet                  ;get interrupt
  33.         mov     WORD _tsr_int21, bx     ;save segment
  34.         mov     WORD _tsr_int21+2, dx   ;save offset
  35.  
  36. ;--- hook new interrupt
  37.  
  38.         mov     al, 21H                 ;interrupt number
  39.         mov     dx, ds                  ;segment
  40.         mov     bx, OFFSET _tsr_dos     ;offset
  41.         call    IntSet                  ;set interrupt
  42.         ENDM
  43.  
  44. ;========================================
  45. ; Macro to unhook the INT 21H handler.
  46. ;
  47. ; In: seg= TSR segment address in a
  48. ;          register or variable.
  49.  
  50. Free21  MACRO   seg
  51.         push    ds
  52.         mov     ds, seg
  53.         mov     bx, WORD _tsr_int21     ;load offset
  54.         mov     dx, WORD _tsr_int21+2   ;load segment
  55.         pop     ds
  56.         mov     al, 21H                 ;interrupt number
  57.         call    IntSet                  ;restore interrupt
  58.         ENDM
  59.  
  60. ;========================================
  61. ; Macro to check that INT 21 can be
  62. ; unhooked with Free21.
  63. ;
  64. ; In: seg= TSR segment address in a
  65. ;          register or variable.
  66. ;
  67. ; Out: ZY= set if okay.
  68.  
  69. Okay21  MACRO   seg
  70.         push    seg
  71.         mov     al, 21H                 ;interrupt number
  72.         call    IntGet                  ;get interrupt address
  73.         pop     ax
  74.         cmp     bx, OFFSET _tsr_dos     ;check offset
  75.         jne     _oky211
  76.         cmp     dx, ax                  ;check segment
  77. _oky211
  78.         ENDM
  79.  
  80. ;========================================
  81. ; Macro to query a resident TSR.
  82. ;
  83. ; In: code= query function code.
  84. ;
  85. ; Out: CY= set if no response from TSR.
  86.  
  87. Query   MACRO   code
  88.         IFN     TYPE(code) = TYPE()
  89.         mov     al, code                        ;code
  90.         ENDIF
  91.         mov     ah, 2BH                         ;set date function
  92.         mov     cx, TSR_ID1                     ;id one
  93.         mov     dx, TSR_ID2                     ;id two
  94.         int     21H                             ;execute
  95.         sub     al, 1                           ;carry set if okay
  96.         cmc                                     ;carry set if error
  97.         ENDM
  98.  
  99. ;========================================
  100. ; Interrupt 21H handler.
  101.  
  102. _tsr_dos PROC   FAR
  103.         cmp     ah, 2Bh                 ;check set date function
  104.         jne     _tsrdo4
  105.         cmp     cx, TSR_ID1             ;check if first id matches
  106.         jne     _tsrdo4
  107.         cmp     dx, TSR_ID2             ;check if second id matches
  108.         jne     _tsrdo4
  109.  
  110. ;--- external query
  111.  
  112.         push    bx
  113.         mov     bx, OFFSET TsrUsr       ;user function table
  114.         jmps    _tsrdo2
  115.  
  116. _tsrdo1 add     bx, 3                   ;next table entry
  117. _tsrdo2 seg     cs
  118.         cmp     BYTE [bx], 0            ;check if end of table
  119.         je      _tsrdo3                 ;exit if so
  120.         seg     cs
  121.         cmp     [bx], al                ;check if command matches
  122.         jne     _tsrdo1                 ;loop back if not
  123.         seg     cs
  124.         mov     ax, [bx + 1]            ;load routine
  125.         pop     bx
  126.  
  127.         push    ds
  128.         push    es
  129.         mov     dx, cs
  130.         mov     ds, dx                  ;load data segments
  131.         mov     es, dx                  ;
  132.         call    ax                      ;call routine
  133.         pop     es
  134.         pop     ds
  135.  
  136.         sub     al, al                  ;clear error
  137.         clc                             ;no carry
  138.         ret     2                       ;exit
  139.  
  140. ;--- invalid resident function
  141.  
  142. _tsrdo3 pop     bx
  143.         mov     al, 0FFH                ;return error
  144.         stc
  145.         ret     2
  146.  
  147. ;--- branch to old DOS
  148.  
  149. _tsrdo4 seg     cs
  150.         jmp     _tsr_int21              ;branch to dos handler
  151.         ENDP
  152.  
  153. _tsr2_end
  154.